<template>
  <div v-loading="loading">
    <div class="top display-flex justify-content align-items">
      新闻资讯
    </div>
    <div class="content">
      <div class="title"></div>
      <div class="news">
        <el-card shadow="hover" v-for="(list,index) in newsList" :key="index">
          <div class="display-flex space-between flex-item">
            <div style="width: 260px;height: 260px;overflow: hidden;">
              <img :src="list.image" height="260" :alt="list.name" title=""/>
            </div>
            <div class="message">
              <p class="ellipsis ellipsis_more ellipsis_more_1">{{list.name}}</p>
              <p class="ellipsis ellipsis_more_3">{{list.description}}</p>
              <router-link :to="{ name: 'newsMess', params: { id: list.id } }">查看详情</router-link>
            </div>
            <div class="time tx-r display-flex align-items">
              <div>
                <p>{{list.create_time_text}}</p>
              </div>
            </div>
          </div>
        </el-card>

        <div class="tx-c page">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next"
            :total="total"
            background>
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "news",
    data() {
      return {
        loading: false,

        pageSize: 10,   //每页几条
        currentPage: 1,//当前第几页
        total:0,  //总共条数

        newsList:[],
        timeY: '',
        timeD: '',
      }
    },
    methods: {
      //每页几条
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.getNewsList(1);
      },
      //当前第几页
      handleCurrentChange(val) {
        // console.log(val)
        // console.log(`当前页: ${val}`);
        this.currentPage = val
        this.getNewsList(this.currentPage)
      },
      //获取列表
      getNewsList(page) {
        let that = this;
        this.$http
          .post(this.$api.default.ZX,{page : page,listRows:this.pageSize})
          .then(res => {
            console.log('数据', res);
            this.total = res.data.total;
            for(var i = 0;i < res.data.data.length;i++){
              res.data.data[i].image = that.$api.default.url_ + res.data.data[i].image;
              res.data.data[i].create_time_text = res.data.data[i].create_time_text.substring(0,10);
            }
            that.newsList = res.data.data;

          }).catch(error => {
        })
          .then(() => {
          });
      },
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.getNewsList(this.currentPage)
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {}, //生命周期 - 创建之前
    beforeCreate() {},
    //生命周期 - 挂载之前
    beforeMount() {},
    //生命周期 - 更新之前
    beforeUpdate() {},
    //生命周期 - 更新之后
    updated() {},
    //生命周期 - 销毁之前
    beforeDestroy() {},
    //生命周期 - 销毁完成
    destroyed() {},
    //如果页面有keep-alive缓存功能，这个函数会触发
    activated() {},
  }
</script>

<style scoped>
  .top{
    height: 500px;
    min-width: 1200px;
    background: url("../assets/image/banner5.png") no-repeat;
    background-position: center center;
    background-size: cover;
    box-sizing: border-box;
    font-size: 50px;
    color: #FFFFFF;
  }
  .top p{
    font-size: 50px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #FFFFFF;
    line-height: 60px;
    text-align: center;
    margin-bottom: 60px;
  }
  .content{
    width: 1200px;
    margin: auto;
  }
  .title{
    text-align: center;
    font-size: 32px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #1890FF;
    /*line-height: 84px;*/
    margin: 70px 0;
  }
  .title span{
    display: inline-block;
    margin: 0 20px;
  }
  .news >>> .el-card{
    margin-bottom: 20px;
  }
  .news img{
    border-radius: 10px;
    /*max-width: 260px;*/
  }
  .message{
    width: 600px;
    margin-left: 10px;
    color: #333333;
    padding-right: 80px;
    box-sizing: border-box;
  }
  .message p:nth-of-type(1){
    font-size: 22px;
    line-height: 28px;
    margin-bottom: 30px;
  }
  .message p:nth-of-type(2){
    font-size: 16px;
    line-height: 28px;
    margin-bottom: 30px;
  }
  .message a:nth-child(3){
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #1890FF;
    line-height: 28px;
  }
  .time{
    width: 170px;
    color: #999999;
  }
  .time p:nth-of-type(1){
    font-size: 22px;
  }
  .time p:nth-of-type(2){
    font-size: 16px;
  }
  .time > div{
    width: 100%;
    padding: 10px 0;
    border-left: solid 1px #999;
  }
  .page{
    margin: 60px auto 70px;
  }
</style>
